function f_exe_alter_sql()
{   #执行alter的函数, 部分ddl可以直接执行alter(只修改了元数据的操作)
    declare res_log_test res_log has_tmp_table_name _is_renamed fun_name
    fun_name="f_exe_alter_sql"
    res_log_test="${osc_test_res_log_dir}/alter.$(awk -F/ '{print $NF}' <<< "${sql_file}").test.log"
    res_log="${osc_execute_res_log_dir}/alter.$(awk -F/ '{print $NF}' <<< "${sql_file}").log"
    tmp_table_name="${1}"
    __="select count(*) from ${isdbt} where table_name = '${tmp_table_name}' and table_schema = '${mysql_db}'"
    __="$(f_exe_sql_in_mysql "${__}" "" "" "" "$(eval echo ${log_addr})")" #判断rename的目标表是否存在
    _is_renamed="$(grep -B $(wc -l < ${alter_file_tmp2}) "${line}" ${alter_file_tmp2}|grep -icPw "alter *table *[\`]?${tmp_table_name}[\`]? *rename ")"
    if [ "${__}x" != "0x" ] && [ "${_is_renamed}x" == "0x" ] && [ "${execute}x" == "1x" ] #_is_renamed=非0表示这行之前已经将这个目标表rename走了
    then #如果目标表已经存在就退出改表
        __="${tmp_table_name} 表在 '${mysql_host}:${mysql_port}' 已经存在 ] [ ERROR 1050 (42S01) at line 1: Table '${tmp_table_name}' already exists ]"
        f_logging "$(eval echo ${log_addr}):ERROR" "${__} [ ${line}" "2" "1"
    fi
    flagFile="${script_execute_mark_dir}/alter.panic.${mysql_host}.${mysql_port}.${mysql_db}.${_t_}.flag.${_PPID}"
    pause_file_name="${script_execute_mark_dir}/$(md5sum <<< "${flagFile}"|awk '{print $1}')_pause"
    unset flagFile
    f_check_work_is_run "alter" "${_t_}"
    f_logging "$(eval echo ${log_addr}):REMAIND" "本次改表在测试环境执行的操作 ] [ ${line}" "execute:${execute}"
    if [ "${execute}x" == "0x" ]
    then
        __="$(f_exe_sql_in_test_mysql "show create table ${test_db}.${t_tmp}\G" "" "$(eval echo ${log_addr})")"
        echo "${__}" >> ${log_file}
    fi
    f_logging "$(eval echo ${log_addr}):REMAIND" "如下是改表前的表结构 ] [ ${__} ] [ ${line}" "execute:${execute}" >/dev/null
    f_logging "$(eval echo ${log_addr}):REMAIND" "开始在测试环境改表操作" "execute:${execute}"
    f_exe_sql_in_test_mysql "${line}" "" "$(eval echo ${log_addr})" > ${res_log_test} 2>&1 && osc_exe_state="${?}" || osc_exe_state="${?}"
    if [ ${osc_exe_state} -eq 0 ]
    then
        [ "${global_rename_table}x" == "1x" ] && t_tmp="$(awk '{print $NF}' <<< "${line}"|sed 's/;//g')"
        if [ -z "${tmp_table_name}" ]
        then
            __="$(f_exe_sql_in_test_mysql "show create table ${test_db}.${t_tmp}\G" "" "$(eval echo ${log_addr})")"
            f_check_index_info "${t_tmp}"
        else
            __="$(f_exe_sql_in_test_mysql "show create table ${test_db}.\`${t_tmp}\`\G" "" "$(eval echo ${log_addr})")"
            f_check_index_info "${tmp_table_name}"
            f_check_table_for_batch "${tmp_table_name}"
        fi

        echo "${__}" >> ${log_file}
        f_logging "$(eval echo ${log_addr}):REMAIND" "如下是改表后的表结构 ] [ ${__}" "execute:${execute}" >/dev/null

        f_update_onlineddl_state_to_table_info "true" "预执行成功" "${_t_}"
        f_logging "$(eval echo ${log_addr}):INFO" "在测试环境 '${test_host}:${test_port}' 执行成功 ] [ ${line}" "execute:${execute}"
        f_check_table_after_ddl "${_t_}"
        if [ "${execute}x" != "1x" ]
        then
            {
                [ -f "${osc_run_mark_file}" ] && chattr -i ${osc_run_mark_file} && rm -f ${osc_run_mark_file}
                [ -f "${script_queue_file}" ] && rm -f "${script_queue_file}"
            } || true
            f_check_big_query "改表" "${_t_}" || true
            return 0
        fi
    else
        {
            [ -f "${osc_run_mark_file}" ] && chattr -i ${osc_run_mark_file} && rm -f ${osc_run_mark_file}
            [ -f "${script_queue_file}" ] && rm -f "${script_queue_file}"
        } || true
        if [ "${execute}x" != "1x" ]
        then
            __="$(tail -100 ${res_log_test}|sed "s/${mysql_pass}/xxxxxx/g"|grep -iw "ERROR"|tail -1)"
            f_update_onlineddl_state_to_table_info "true" "预执行失败, 失败原因如下:${__}, 请联系值班dba" "${_t_}"
            exe_sql_get_error_info_list+=("${__} ] [ ${line}") || true
            return 0
        else
            if [ ${osc_exe_state} -eq 124 ]
            then
                f_update_onlineddl_state_to_table_info "true" "预执行失败, 失败原因执行超时, 请联系值班dba" "${_t_}"
                f_record_info_to_dbadb "alter" "${_t_}" "测试环境执行${exe_time}超时. 详情请看${localhost_ip}:${res_log_test}" || true
                f_logging "$(eval echo ${log_addr}):ERROR" "在环境环境 '${test_host}:${test_port}' 执行${exe_time}超时, 执行online ddl过程中可能遇到所等待. ] [ ${line}" "2"
            else
                f_update_onlineddl_state_to_table_info "true" "预执行失败, 遇到未知失败, 请联系值班dba" "${_t_}"
                f_record_info_to_dbadb "alter" "${_t_}" "测试环境执行遇到未知失败. 详情请看${localhost_ip}:${res_log_test}" || true
                f_logging "$(eval echo ${log_addr}):ERROR" "在环境环境 '${test_host}:${test_port}' 执行失败, 详情请看 '${res_log_test}' ] [ ${line}" "2"
            fi
            f_exit "1"
        fi
    fi

    f_check_big_query "改表" "${_t_}" || f_exit "1"
    #这部分注释请参见上面f_exe_osc_comm函数的注释
    {
        touch ${check_mdl_mark_file} && first_check_mdl_mark=3 && sleep 0.2 && wait_mdl_time=$((${check_mdl_timeout}-5))
        f_check_mdl_lock "${mysql_host}" "master" "${mysql_db}" "${_t_}" "${_PPID}" "null" "alter" || true
        { [ -f "${check_mdl_mark_file}" ] && rm -f ${check_mdl_mark_file};} || true
        [ -f "${check_connect_file}" ] && rm -f ${check_connect_file}
        [ -f "${check_thread_file}" ] && rm -f ${check_thread_file}
    } >> ${log_file} &

    { f_check_daemonize "alter" "${_t_}" || true;} &

    f_logging "$(eval echo ${log_addr}):REMAIND" "本次改表在线上环境执行的操作 ] [ ${line}"

    __="$(f_exe_sql_in_mysql "show create table ${mysql_db}.${t_tmp}\G" "" "" "" "$(eval echo ${log_addr})")"
    echo "${__}" >> ${log_file}

    f_logging "$(eval echo ${log_addr}):REMAIND" "如下是改表前的表结构 ] [ ${__} ] [ ${line}" >/dev/null

    f_logging "$(eval echo ${log_addr}):REMAIND" "开始在线上环境改表操作"

    exe_time_tmp="${exe_time}" #先保存超时时间10s, 因为清理临时表的时候加大执行时间, 执行完毕再还原
    if [ "${global_is_supp_add_uk}x" == "truex" ]
    then
        exe_time="180s"
    fi

    f_exe_sql_in_mysql "${line}" "" "" "" "$(eval echo ${log_addr})" > ${res_log} 2>&1 && osc_exe_state="${?}" || osc_exe_state="${?}"
    exe_time="${exe_time_tmp}"

    sleep 1
    f_logging "$(eval echo ${log_addr}):REMAIND" "注 : 改表在线上环境执行完成, 但是不代表任务执行成 ] [ ${line}"
    #改表任务结束, 删除标志文件, 这个文件删除以后检查mdl状态的任务基本就结束了(可能存在几秒延迟)
    { [ -f "${osc_run_mark_file}" ] && chattr -i ${osc_run_mark_file} && rm -f ${osc_run_mark_file};} || true

    f_logging "$(eval echo ${log_addr}):WARN" "等待mdl检查任务结束, 如果需要手动终止检查mdl任务可以删除'${check_mdl_mark_file}'文件"
    for (( wait_time=0; wait_time<120; wait_time++ ))
    do
        sleep 1
        [ ! -f "${check_mdl_mark_file}" -a ! -f "${check_connect_file}" ] && break
    done

    { 
        [ -f "${check_mdl_mark_file}" ] && rm -f ${check_mdl_mark_file}
        [ -f "${check_connect_file}" ] && rm -f ${check_connect_file}
    } || true

    f_logging "$(eval echo ${log_addr}):INFO" "mdl检查任务完成"

    [ -f "${pause_file_name}" ] && osc_exe_state="-1"
    [ -f "${has_max_process_file}" ] && osc_exe_state="-2"

    if [ ${osc_exe_state} -eq 0 ]
    then
        if [ -z "${tmp_table_name}" ]
        then
            __="$(f_exe_sql_in_mysql "show create table ${_mysql_db_}.${t_tmp}\G" "" "" "" "$(eval echo ${log_addr})")"
        else
            __="$(f_exe_sql_in_mysql "show create table ${_mysql_db_}.\`${t_tmp}\`\G" "" "" "" "$(eval echo ${log_addr})")"
        fi
        echo "${__}" >> ${log_file}
        f_logging "$(eval echo ${log_addr}):REMAIND" "如下是改表后的表结构 ] [ ${__}" >/dev/null
        f_logging "$(eval echo ${log_addr}):INFO" "在线上环境 '${mysql_host}:${mysql_port}' 执行成功 ] [ ${line}"
    elif [ "${osc_exe_state}x" == "-1x" ]
    then
        f_record_info_to_dbadb "alter" "${_t_}" "遇到mdl等待. 详情请看${localhost_ip}:${res_log}" || true
        f_logging "$(eval echo ${log_addr}):ERROR" "在线上环境 '${mysql_host}:${mysql_port}' 遇到mdl等待, 终止任务 ] [ ${line}" "2" "1"
    elif [ "${osc_exe_state}x" == "-2x" ] && [ "$(cat ${has_max_process_file})x" == "threadx" ]
    then
        f_record_info_to_dbadb "alter" "${_t_}" "活跃连接数过高. 详情请看${localhost_ip}:${res_log}" || true
        f_logging "$(eval echo ${log_addr}):ERROR" "在线上环境 '${mysql_host}:${mysql_port}' 遇到活跃连接数过高, 终止任务 ] [ ${line}" "2" "1"
    elif [ "${osc_exe_state}x" == "-2x" ] && [ "$(cat ${has_max_process_file})x" == "connectx" ]
    then
        f_record_info_to_dbadb "alter" "${_t_}" "连接数过高. 详情请看${localhost_ip}:${res_log}" || true
        f_logging "$(eval echo ${log_addr}):ERROR" "在线上环境 '${mysql_host}:${mysql_port}' 遇到连接数过高, 终止任务 ] [ ${line}" "2" "1"
    elif [ ${osc_exe_state} -eq 124 ]
    then
        grep -E "USER : ${mysql_user}|当前任务信息如下" ${res_log} || true
        __="在线上环境 '${mysql_host}:${mysql_port}' 执行${exe_time}超时, 执行online ddl过程中可能遇到锁等待, 稍后请点击重试按钮或者找DBA进行跟进处理."
        f_kill_alter_sql "${mysql_host}" "${mysql_port}" "${mysql_user}" "${_t_}" || true
        f_record_info_to_dbadb "alter" "${_t_}" "执行${exe_time}超时. 详情请看${localhost_ip}:${res_log}" || true
        f_logging "$(eval echo ${log_addr}):ERROR" "${__} ] [ ${line}" "2" "1"
    else
        __="在线上环境 '${mysql_host}:${mysql_port}' 执行失败"
        f_record_info_to_dbadb "alter" "${_t_}" "未知错误. 详情请看${localhost_ip}:${res_log}" || true
        f_logging "$(eval echo ${log_addr}):ERROR" "${__}, 详情请看 '${res_log}' ] [ ${line}" "2" "1"
    fi
    return 0
}

